home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOB003.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-24  |  3KB  |  85 lines

  1. program DemoB003;
  2. {------------------------------------------------------------------------------
  3.                               DBase File Lister
  4.                                    Sample 3
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.        This program demonstrates how dBase files may be listed using
  16.        Griffin Solutions units.
  17.  
  18.        If the DEMOB1.DBF file does not exist, the program will display a
  19.        a message that the file was not found and to run DEMOB001 to make
  20.        the file.
  21.  
  22.        The program initializes a dBase file object, opens the file, and
  23.        proceeds to list selected fields from each record.
  24.  
  25.        The NumberGet, DateGet, and StringGet commands are shown in the
  26.        example.  This is intended to contrast them with the basic FieldGet
  27.        command used to get the field image directly from disk.
  28.  
  29.        The ValueGet Procedure returns the actual numeric value in the field.
  30.        This should be used on Number fields only as it returns a real value.
  31.  
  32.        The DateGet Function is used to retrieve a longint Julian Date from
  33.        the date field.  See GS_DATE.PAS for an explanation of Julian Dates.
  34.  
  35.        The StringGet Function returns the trimed string.
  36.  
  37.        GS_Date_View is used to display a 'viewable' date from the longint
  38.        Julian Date value retrieved by DateGet.
  39.  
  40. -------------------------------------------------------------------------------}
  41.  
  42. uses
  43.    CRT,
  44.    DOS,
  45.    GS_Date,
  46.    GS_dBase,
  47.    GS_DBFld,
  48.    GS_FileH;
  49. var
  50.    MyFile  : GS_dBFld_Objt;
  51.    rnum    : real;
  52.    dnum    : longint;
  53.    ftest   : file;
  54. begin
  55.    GS_Date_Century := true;     {Gives full century on date display (YYYY)}
  56.                                 {default is false for YY only.}
  57.    ClrScr;
  58.    if not GS_FileExists(ftest, 'DEMOB1.DBF') then
  59.    begin
  60.       writeln('File DEMOB1.DBF not found.  Run DEMOB001 to create.');
  61.       halt;
  62.    end;
  63.                        {The 'Real' example starts here}
  64.  
  65.    MyFile.Init('DEMOB1');          {Initialize object using the dBase III}
  66.                                   {file DEMOB1.  DBF Extension assumed}
  67.    MyFile.Open;                   {Open the object's file}
  68.    MyFile.GetRec(Top_Record);     {Get the first record in the file}
  69.    while not MyFile.File_EOF do   {Repeat until end-of-file}
  70.    begin
  71.       rnum := MyFile.NumberGet('PAYMENT');  {use for math later}
  72.       dnum := MyFile.DateGet('BIRTHDATE');  {use for conversion later}
  73.  
  74.       writeln(MyFile.StringGet('LASTNAME'),', ',
  75.               MyFile.StringGet('FIRSTNAME'),'  ',
  76.               GS_Date_View(dnum),' [',
  77.               MyFile.StringGet('PAYMENT'),']',
  78.               rnum/12:8:2);                        {PAYMENT / 12}
  79.       MyFile.GetRec(Next_Record); {Get the next sequential record}
  80.    end;
  81.    MyFile.Close;
  82.    write('Press any Key to continue:');
  83.    repeat until KeyPressed;
  84. end.
  85.